<template>
	<view class="content">
		<uni-search-bar 
			radius="100" 
			:placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" 
			@confirm="search($event, 'search')"
			@cancel="search($event, 'cancel')" 
			@clear="search($event, 'cancel')"
		/>
		<mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="data-list" v-for="(item, key) in dataList" :key="key" @click="toInfo(item)">
				<view class="data-image">
					<image :src="$getImg(item.picture, 'pic')"></image>
				</view>
				<view class="data-item">
					<view class="item-text item-more two-sides">
						<view class="item-title">{{item.title}}</view>
						<view class="item-state">
							<uni-tag
								inverted 
								:type="item.status | codeFormat(publishOptions,'type')"
								:text="item.status | codeFormat(publishOptions)">
							</uni-tag>
						</view>
					</view>
					<view class="item-text item-desc">
						{{$t('app.other.publicType')}}：{{item.publicItem | codeFormat(publicOptions)}}
					</view>
					<view class="item-text item-more two-sides">
						<view class="item-desc">{{$t('app.other.publisher')}}：{{item.userName}}</view>
						<view class="item-time">{{item.publicDate | dateFormat('yyyy-MM-dd')}}</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js"
	import { getNoticeList } from '@/api/platform/common.js'
	import constants from '@/utils/constants.js'
	
	export default {
		mixins: [MescrollMixin],
		onLoad() {
			
		},
		data() {
			return {
				dataList: [],
				searchText: '',
				publicOptions: constants.publicOptions,
				publishOptions: constants.publishOptions
			}	
		},
		methods: {
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				const pager = {
					start: page.num,
					limit: page.size
				}
				
				let params = []
				if(this.searchText) {
					params.push({
						key: "Q^TITLE_^SL",
						value: this.searchText
					})
				}
				
				getNoticeList(pager, params).then(res =>{
					let curPageData = res.data.dataResult;
					let curPageLen = curPageData.length; 
					let totalSize = res.data.pageResult.totalCount;
					if(page.num == 1){
						//如果是第一页需手动置空列表
						this.dataList = [];
					}
					this.dataList = this.dataList.concat(curPageData); //追加新数据
					this.mescroll.endBySize(curPageLen, totalSize); 
				})
			},
			// 点击列表查看详情
			toInfo(item) {
				uni.navigateTo({
					url: '/pages/platform/notice/detail?noticeId='+item.id
				})
			},
			search1(e) {
				this.searchText = e.value
				this.mescroll.resetUpScroll()
			},
			search2(e) {
				this.searchText = ''
				this.mescroll.resetUpScroll()
			}
		}
	}
</script>

<style lang="scss">	
	@import '@/static/style/common-list.scss';
</style>
